package com.jwiki.app.jkeeper.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jwiki.app.jkeeper.common.data.Response;
import com.jwiki.app.jkeeper.controller.form.CategoryForm;
import com.jwiki.app.jkeeper.service.CategoryService;

@RestController
@RequestMapping("/category")
public class CategoryController extends BaseController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/saveCategory")
    public Response saveCategory(@RequestBody CategoryForm form) {
        Response response = getResponse();
        response.setSuccess(categoryService.saveCategory(form));
        return response;
    }

    @RequestMapping("/getCategory")
    public Response getCategory(@RequestBody CategoryForm form) {
        Response response = getResponse();
        response.setData(categoryService.getCategory(form));
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getCategoryByPage")
    public Response getCategoryByPage(@RequestBody CategoryForm form) {
        Response response = getResponse();
        response.setData(categoryService.getCategoryByPage(form));
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/removeCategory")
    public Response removeCategory(@RequestBody List<Long> categoryIds) {
        Response response = getResponse();
        response.setSuccess(categoryService.removeCategory(categoryIds));
        return response;
    }

    @RequestMapping("/getSubCategory")
    public Response getSubCategory(@RequestBody CategoryForm form) {
        Response response = getResponse();
        response.setData(categoryService.getSubCategory(form));
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getParentCategory")
    public Response getParentCategory(@RequestBody CategoryForm form) {
        Response response = getResponse();
        response.setData(categoryService.getParentCategory(form));
        response.setSuccess(true);
        return response;
    }

}
